package com.xky.beetlsql.service;

import com.xky.beetlsql.dao.AccountDao;
import com.xky.beetlsql.entity.Account;
import org.beetl.sql.core.SQLManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author keying.xia
 * @date 2017/12/11
 */
@Service
public class AccountService {

    @Autowired
    private AccountDao accountDao;

    public Account getAcccountByID(Integer id){
       return accountDao.single(id);
    }

    public void addAccount(Account account){
        accountDao.insert(account);
    }

    public void deleteAccount(Integer id){
        accountDao.deleteById(id);
    }

    public int updateAccount(Integer id, Account account){
        Account accountOld = accountDao.single(id);
        accountOld.setAge(account.getAge());
        accountOld.setName(account.getName());
        int result = accountDao.updateById(accountOld);
        return result;
    }

    public List<Account> getAccountList(){
        return accountDao.all();
    }


    public Account getAccountByName(String name){
        return accountDao.getAccountByName(name);
    }


    public List<Account> getAccountsByAge(Integer minAge,Integer maxAge){
        return accountDao.getAccountByAge(minAge,maxAge);
    }

    public List<Account> getAccountsLikeName(String name){
        return accountDao.getAccountLikeName(name);
    }

    public List<Account> getAccounts(){
        return accountDao.getAccounts();
    }

}
